﻿using System;
using System.Runtime.Serialization;
using System.Globalization;

using Fuse8.DomainFramework.Domain;

namespace Fuse8.DomainFramework.Common.Exceptions
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class EntityCommandParameterMismatchException : InvalidOperationException
    {
        #region Constructors

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="expectedParameter"></param>
        public EntityCommandParameterMismatchException(IEntityCommandParameter parameter, string expectedParameter)
            : this(BuildException(parameter, expectedParameter))
        { }

        /// <summary>
        /// 
        /// </summary>
        public EntityCommandParameterMismatchException()
            : base()
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public EntityCommandParameterMismatchException(string message)
            : base(message)
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="innerException"></param>
        public EntityCommandParameterMismatchException(string message, Exception innerException)
            : base(message, innerException)
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected EntityCommandParameterMismatchException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        { } 

        #endregion

        private static string BuildException(IEntityCommandParameter parameter, string expectedParameter)
        {
            Guard.ArgumentNotNull(parameter, "command");

            return string.Format(CultureInfo.CurrentUICulture, "Command {0} type isn't expected. Expected type is {1}", parameter.GetType().Name, expectedParameter);
        }
    }
}
